pub(crate) mod user {
    use sea_orm::EntityTrait;
    use crate::common::common::common::{add, opp, Person};
    use crate::types::common_resp::common_resp::RequestResult;
    use actix_web::{web, HttpResponse, Responder};
    use pkg::entity::t_account;
    use sea_orm::DatabaseConnection;
    use serde::Deserialize;
    use web::Data;

    // 一个简单的用户路由处理函数
    async fn index() -> impl Responder {
        HttpResponse::Ok().body("Hello from user routes!")
    }


    async fn tr() -> impl Responder {
        let rt =RequestResult{code:0, message:"ok".to_string(), data: () };
        HttpResponse::Ok().json(rt)
    }

    #[derive(Deserialize)]
    pub struct MyData {
        id: u32,
    }
    pub async fn get_account(
        db: Data<DatabaseConnection>,
        paramas: web::Json<MyData>,
    ) -> impl Responder {
        let account = t_account::Entity::find_by_id(paramas.id).one(db.get_ref()).await;
        match account {
            Ok(Some(account_data)) => HttpResponse::Ok().json(account_data),
            Ok(None) => HttpResponse::NotFound().finish(),
            Err(_) => HttpResponse::InternalServerError().finish(),
        }
    }



    async fn echo(req_body: String) -> impl Responder {
        let myperson = Person{ name: "Alice".to_string(), age: 30 };
        println!("{}", req_body);
        println!("11:{}", add(1,2).to_string());
        println!("{}", opp(2));
        HttpResponse::Ok().json(myperson)
    }


    // 配置函数，用于注册路由
    // pub fn configure(cfg: &mut web::ServiceConfig) {
    //     cfg.service(web::scope("/users").route("/index", web::get().to(index)));
    //     cfg.service(web::scope("/users").route("/echo", web::post().to(echo)));
    //     cfg.service(web::scope("/users").route("/api/front/orderNotify", web::post().to(tr)));
    // }

    pub fn config_routes(cfg: &mut web::ServiceConfig) {
        cfg.route("/user/index", web::get().to(index));
        cfg.route("/user/hello", web::post().to(echo));
        cfg.route("/user/account", web::post().to(get_account));
        cfg.route("/user/api/front/orderNotify", web::post().to(tr));
    }
}



